package com.scoy.honeymei.base;


import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.scoy.honeymei.MeApp;

/**
 * @ClassName: BaseActivity$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 14:39$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 14:39$
 * @UpdateRemark: 更新内容
 */
public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MeApp.getInstance().add(this);
    }


    public abstract void initNormal();


    /**
     * 重写 getResource 方法，防止系统字体影响
     */
    @Override
    public Resources getResources() {
        Resources resources = super.getResources();
        if (resources != null && resources.getConfiguration().fontScale != 1.0f) {
            android.content.res.Configuration configuration = resources.getConfiguration();
            configuration.fontScale = 1.0f;
            resources.updateConfiguration(configuration, resources.getDisplayMetrics());
        }
        return resources;
    }


    /**
     * 设置底部虚拟按钮颜色
     */
    public void setBtmColor(int colorInt) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setNavigationBarColor(getResources().getColor(colorInt));

        }
    }

    public void initWeb(WebView wv, String meUrl) {

        wv.loadUrl(meUrl);
        //获得WebSetting,设置js有效
        WebSettings setting = wv.getSettings();
        setting.setJavaScriptEnabled(true);
        //把WebViewHelper的对象，传递到js中，供调用
        //  wv.addJavascriptInterface(new WebViewHelper(), "wvHelper");

        setting.setAppCacheEnabled(true);//启用localstorage本地存储api
        setting.setLightTouchEnabled(true);//启用选中功能
        setting.setDomStorageEnabled(true);//启用dom存储(关键就是这句)，貌似网上twitter显示有问题也是这个属性没有设置的原因
        setting.setDatabaseEnabled(true);//启用html5数据库功能
        setting.setDisplayZoomControls(false); //隐藏webview缩放按钮
        //        webSettings.setBuiltInZoomControls(true); // 显示放大缩小
        //        webSettings.setSupportZoom(true); // 可以缩放

        wv.setWebChromeClient(new WebChromeClient() {
            @Override
            public boolean onJsAlert(WebView view, String url, String message,
                                     JsResult result) {
                // TODO Auto-generated method stub
                return super.onJsAlert(view, url, message, result);
            }
        });

        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });


    }


}
